package proyectoia;

import aima.search.framework.HeuristicFunction;

/**
 */
public class DistFileSystemHeuristicFunction3 implements HeuristicFunction {

    public float similarity;
    public float notServed;

    public DistFileSystemHeuristicFunction3(float similarity, float notServed) {
        this.similarity = similarity;
        this.notServed = notServed;
    }

    @Override
    public double getHeuristicValue(Object s) {
        DistFileSystemState state = (DistFileSystemState) s;
        int n = state.numServers;
        double total = state.getTotalServerTime();
        double mean = total / n;
        double variance = 0;
        for (int i = 0; i < n; i++) {
            variance += (mean - state.getServerTime(i)) * (mean - state.getServerTime(i));
        }
        variance /= n;
        double stdev = Math.sqrt(variance);
//        System.out.println(mean + similarity * stdev + notServed * state.unallocated.size());
//        System.out.println(state.unallocated.size()*notServed + " " + similarity * stdev + " " + mean + " : total "  + mean + similarity * stdev + notServed * state.unallocated.size());
//        System.out.println(state.unallocated.size() + " ->" + (mean + similarity * stdev + (notServed * (state.unallocated.size()/(mean + similarity * stdev)))));
//        System.out.println(mean + similarity * stdev + (notServed * state.unallocated.size()));
//        double pen = notServed * state.unallocated.size();
//        double max = mean;
//        if (mean < pen ) max = pen;
//        System.out.println(notServed * state.unallocated.size()*state.unallocated.size() + " " + (mean + similarity * stdev + (notServed * state.unallocated.size()*state.unallocated.size())));
//        System.out.println(state.unallocated.size());
        return mean + similarity * stdev + (notServed * state.unallocated.size()*state.unallocated.size());
    }
}
